//
//  XMShowWeiboCountView.m
//  XMWeibo
//
//  Created by chi on 14-8-28.
//  Copyright (c) 2014年 xiaoming. All rights reserved.
//


#import "XMShowWeiboCountView.h"

/*** 距离两边的边距 */
#define kEdge (3.0)

@implementation XMShowWeiboCountView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //设置属性
        self.adjustsImageWhenHighlighted = NO;
        self.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [self setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
        [self setBackgroundImage:[UIImage adaptIOS7ImageWithName:@"timeline_new_status_background"] forState:UIControlStateNormal];

        
        //设置位置
        CGFloat naviH = 64.0;//self.navigationController.navigationBar.bounds.size.height + 20.0;
        CGFloat msgBtnH = self.currentBackgroundImage.size.height;
        self.frame = CGRectMake(kEdge, naviH - msgBtnH, [UIScreen mainScreen].applicationFrame.size.width - kEdge * 2, msgBtnH);
    }
    return self;
}

- (void)setRefreshWeiboCount:(NSUInteger)count
{
    if (count < 1) {
        [self setTitle:@"没有新的微博" forState:UIControlStateNormal];
    }
    else {
        [self setTitle:[NSString stringWithFormat:@"%d条新微博", count] forState:UIControlStateNormal];
    }
    
 
    CGFloat naviH = 64.0;
    CGFloat msgBtnH = self.currentBackgroundImage.size.height;
    
    [UIView animateWithDuration:0.5f animations:^{
        CGRect frame = self.frame;
        frame.origin.y = naviH + 2.0;
        self.frame = frame;
    } completion:^(BOOL finished) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0f * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [UIView animateWithDuration:0.5f animations:^{
                CGRect frame = self.frame;
                frame.origin.y = naviH - msgBtnH;
                self.frame = frame;
            } completion:^(BOOL finished) {
                [self removeFromSuperview];
            }];
        });
    }];
}

@end
